<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
	<meta name="author" content="wangyupeng">
	<title>单位卡发卡</title>
	<script language="javascript" src="../script/print.js" type="text/javascript"></script>
	<script language="javascript" src="../script/common.js" type="text/javascript"></script>
	<script language="javascript" src="../script/card.js" type="text/javascript"></script>
	<!--动态js-->
	<script language="javascript" type="text/javascript">
	//页面加载方法
	var qt;	
	var companyUser;
	function load(){
		Eui.showNavigation();
		setPages(["mainview","readcardview","detview"]);
	}
	
	//刷新未发卡司机列表
	function refreshTable(){
		qt.paramFunc = function(){
			var params = {}
			params.batchNo = companyform.batchNo.value;
			return params;
		}
		qt.showTable();
	}
	
	function findCustomizeWarrant(){
		if (!checkForm(companyform)) return;
		var uniqueId = companyform.uniqueId.value;
		var batchNo = companyform.batchNo.value;
		DWR.call("mgntQueryService.checkDrawCompnyCards",uniqueId,batchNo,showCompanyUser,{blockScreen:true})
	}
	
	//选择客户编号编号
	function selCardUser(){
		CardMgnt.selCardUser(function(v){
			companyform.uniqueId.value = v.uniqueId;
		},{cardUserType:CardUserType.COMPANY})
	}
	//显示单位客户信息
	function showCompanyUser(data){
		switchPage("readcardview");
		companyUser = data.cardUser;
		if (companyUser.type != CardUserType.COMPANY){
			showWarning("不是单位帐户！");
			return;
		}
		Common.setValues(companyUserViewForm,CardMgnt.parseCardUser(data));
		
		var columns = [];
		columns[0] = {type:"checkbox"}
		columns[5] = {render:function(v,r){
			if (v)
				return v
			else
				return '定制中'
		}}
		columns[20] = {title:"操作",render:function(v,r){
			return "<a href=# onclick='cardVerify(\""+r[1]+"\",\""+r[5]+"\")'>验 卡</a>"
		}}
		qt = new QueryTable("find_customize_drivers",null,"driversdiv",columns,{
			buttons:[
			]
		});
		refreshTable();
	}
	
	//验卡
	function cardVerify(uniqueId,userAsn){
		var asn;
		try{
			getCard();
			asn = getAsn();
			if (asn != userAsn){
				showError("该卡不是当前帐户的定制卡片");
				return;
			}
		}catch(e){
			showError("验卡失败！");
			if (showQuestion("验卡失败，是否重新定制卡片？")){
				try{
					var data = DWR.syncCall("cardMgntService.recustomizeCard",companyform.uniqueId.value);
					showInformation("重新申请定制卡片成功，等待制卡！");
				}catch(e){
					showError("重新申请定制卡片失败："+e.description);
				}
			}
			return;
		}
		
		DWR.call("cardMgntService.verifyCustomizeCard",asn,uniqueId,function(){
			showInformation("验卡成功！");
		},{blockScreen:true});
	}
	
	//领用卡片
	function receiveCard(){
		var objs = qt.getBoxValue(true);
		if (objs.length<1){showWarning("请选择需要领用的单位卡！");return;}
		var ids = "";
		for(var i=0;i<objs.length;i++){
			var column = objs[i];
			var uniqueId = column[1];
			var asn = column[5];
			var storeStatus = column[9];
			if (!asn){showWarning("客户"+uniqueId+"的卡片处于定制状态，无法领用！");return;}
			if (storeStatus != CardStoreStatus.STORE){showWarning("客户"+uniqueId+"的卡片"+asn+"处于"+Common.getText(CardStoreStatus.CATEGORY,storeStatus)+"状态，无法领用！");return;}
			if (ids) ids += ",";
			ids += column[0];
		}
		if (!showQuestion("是否领用这些单位卡？")) return;
		DWR.call("cardMgntService.customizeDrawCompanyCard",ids,function(data){
			showInformation("单位卡定制卡领用成功！");
			switchPage("detview");
			CardMgnt.showPrintView("detview","customize_draw_company_bill",data.logId,"单位定制卡片领用凭证");
			try{WebPrint.print('billview');}catch(e){showWarning("打印出错："+e.description);return;}
		},{blockScreen:true});
	}
	
	
	//重置
	function onCancel(){
		switchPage("mainview");
		companyUser = null;
		companyUserViewForm.reset();
		companyform.reset();
	}
	
	</script>
</head>
<body onload="load()">
	<!--页面导航-->
	<div class="nav"><div id="nav">&nbsp;</div></div>
	<div id="mainview">
		<div class="form">
			<form id="companyform" name="companyform">
				<div class="formTitle"><div class="l">查询单位客户</div><div class="r">
				</div></div>
				<table cellSpacing=0 cellPadding=4 width="100%" border=0 class="label5">
					<tr>
						<td>
							<label>客户编号</label> <input type="text" name="uniqueId" onblur="checkV(this,'',true)" maxlength="24"><a class="orga" href="#" onclick="selCardUser()">&nbsp;&nbsp;</a><span class="des">*</span>
						</td>
						<td>
							<label>业务流水号</label> <input type="text" name="batchNo" onblur="checkV(this,'',true)" maxlength="18"><span class="des">*</span>
						</td>
						<td>
							<button onclick="findCustomizeWarrant()">查 询</button>
						</td>
					</tr>	
				</table>
			</form>
		</div>
	</div>
	<div id="readcardview" style="display:none;">
		<div class="form">
			<div class="formTitle">单位帐号信息</div>
			<form id="companyUserViewForm" name="companyUserViewForm">
				<input type="hidden" name="cardType">
				<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="col4 label4">
					<tr>
						<td><label>单位名称</label> <input name="name" type="text" readonly class="readonly"></td>
						<td><label>证件类型</label> <input name="idnoTypeText" type="text" readonly class="readonly"></td>
						<td><label>证&nbsp;件&nbsp;号</label> <input name="idno" type="text" readonly class="readonly"></td>
						<td><label>客户编号</label> <input name="uniqueId" type="text" readonly class="readonly"></td>
					</tr>
					<tr>
						<td><label>开户机构</label> <input name="buildFileStation" type="text" readonly class="readonly"></td>
						<td><label>状&nbsp;&nbsp;&nbsp;&nbsp;态</label> <input name="statusText" type="text" readonly class="readonly"></td>
						<td><label>客户级别</label> <input name="currentLevelText" type="text" readonly class="readonly"></td>
						<td><label>卡片类型</label> <input name="cardTypeName" type="text" readonly class="readonly"></td>
					</tr>
				</table>
			</form>
		</div>
		<div id="driversdiv"></div>
		<p>
			<button onclick="receiveCard()">领 用</button>
			<button onclick="onCancel()">返 回</button>
		</p>
	</div>
	<!--凭证页面-->
	<div id="detview" style="display:none;">
	</div>
</body>
</html>